package com.she.iiicoursecenter.adapter;

import java.util.ArrayList;
import java.util.List;

import com.she.iiicoursecenter.R;
import com.she.iiicoursecenter.iiiApplication;
import com.she.iiicoursecenter.event.connect.bean.GetContentListBean;
import com.she.iiicoursecenter.event.connect.bean.GetItemListBean;
import com.she.iiicoursecenter.view.KenTextView;

import ken.app.helper.Helper;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class Tab1_CourseSetAdapter extends GeneralAdapter {
	
	static List<GetContentListBean> mDataList;
	static Handler mhandler;
	static GenSelectAllListItemView mGenSelectAllView = new GenSelectAllListItemView();
	
	public Tab1_CourseSetAdapter(Context context, List<?> dataList ) {
		super(context, mGenSelectAllView);
		mDataList = (List<GetContentListBean>) dataList;
//		mhandler = handler;
		this.setData(mDataList);
	}
			
	public static class GenSelectAllListItemView extends GenView{
		LayoutInflater inflater;
		
		@Override
		protected View genBody(Context context, View convertView,final Object element, final int position) {
						
			if (inflater == null) {
				inflater = LayoutInflater.from(context);
			}
			final ViewHolder holder;
			if (convertView != null	&& convertView.getTag() instanceof ViewHolder) 
			{
				holder = (ViewHolder) convertView.getTag();
			} else 
			{
				convertView = inflater.inflate(R.layout.tab1_raw, null);
				holder = new ViewHolder();
				holder.title = (KenTextView) convertView.findViewById(R.id.raw_title);
				holder.raw_color = convertView.findViewById(R.id.raw_color);
				convertView.setTag(holder);
			}
			
			holder.title.setKenText(((GetContentListBean) element).getContentName());
//			if (((GetContentListBean) element).getContentName().length() >= 11 ) {
//				holder.title.setTextSize(18);
//			}
//			if (((GetContentListBean) element).getContentName().length() >= 12) {
//				holder.title.setText(((GetContentListBean) element).getContentName().substring(0, 11)+"...");
//			}
			int colorCount = ((iiiApplication)context.getApplicationContext()).itemListColorCount;
			if (colorCount % 5 == 0) {
				holder.raw_color.setBackgroundResource(R.drawable.raw_t_green);
			} else if (colorCount % 5 == 1) {
				holder.raw_color.setBackgroundResource(R.drawable.raw_t_yellow);
			} else if (colorCount % 5 == 2) {
				holder.raw_color.setBackgroundResource(R.drawable.raw_t_orange);
			} else if (colorCount % 5 == 3) {
				holder.raw_color.setBackgroundResource(R.drawable.raw_t_purple);
			} else if (colorCount % 5 == 4) {
				holder.raw_color.setBackgroundResource(R.drawable.raw_t_blue);
			}
			
			return convertView;
		}
		
		private class ViewHolder {
			KenTextView title;
			View raw_color;
		}
	}
	
}
